package com.chenfwind.bookclub.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

import com.chenfwind.bookclub.R;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.params.HttpClientParams;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.apache.http.params.HttpProtocolParams;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

/**
 * Created by mufeng on 2016/4/18.
 */
public class register extends Activity implements RadioGroup.OnCheckedChangeListener {

    private HttpParams httpParams;
    private HttpClient httpClient;

    private Button registerButton;
    private EditText userNameET;
    private EditText passwordET;
    private EditText password_again_ET;
    private EditText nickNameET;
    private RadioGroup genderRG;
    private TextView toLogin;

    private String userName;
    private String password;
    private String password_again;
    private String nickName;
    private int gender;
    private List<NameValuePair> params;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_register);

        registerButton = ( Button ) findViewById(R.id.register_subBtn);
        userNameET = ( EditText ) findViewById(R.id.register_accountEt);
        passwordET = ( EditText ) findViewById(R.id.register_pwdEt);
        password_again_ET = ( EditText ) findViewById(R.id.register_pwdEt_again);
        nickNameET = ( EditText ) findViewById(R.id.register_nickName);
        genderRG = ( RadioGroup ) findViewById(R.id.register_gender_radio);
        toLogin = ( TextView ) findViewById(R.id.id_tv_toLogin);

        toLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(register.this , login.class);
                startActivity(intent);
                finish();
            }
        });

        init();

        genderRG.setOnCheckedChangeListener(this);

        registerButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                userName = userNameET.getText().toString();
                password = passwordET.getText().toString();
                nickName = nickNameET.getText().toString();
                params = new ArrayList<NameValuePair>();
                params.add(new BasicNameValuePair("userName",userName));
                params.add(new BasicNameValuePair("password",password));
                params.add(new BasicNameValuePair("nickName",nickName));
//                params.add(new BasicNameValuePair("gender",gender));
                Map params2 = new HashMap();
                params2.put("hl","zh-CN");
                params2.put("source","hp");
                String url = "";


            }
        });
    }



    private void init(){

    }

    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {
        switch (checkedId){
            case R.id.register_gender_man :
                gender = 1;
                break;
            case R.id.register_gender_woman :
                gender = 0;
                break;
        }
        Toast.makeText(register.this, ""+gender, Toast.LENGTH_SHORT).show();
    }



}
